package com.example.yunJie.digitalSentry.control;


import com.example.yunJie.digitalSentry.entity.ShiftEntity;
import com.example.yunJie.digitalSentry.service.MarketService;
import com.example.yunJie.digitalSentry.service.PostService;
import com.example.yunJie.digitalSentry.service.ShiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Shift")
public class ShiftControl {

    @Autowired
    private ShiftService shiftService;

    @Autowired
    private MarketService marketService;

    @Autowired
    private PostService postService;


    @RequestMapping("/add")
    public void  insert(ShiftEntity shiftEntity){
        shiftEntity.setMarketId(String.valueOf(marketService.findIdByMarketName(shiftEntity.getMarketName()).getId()));
        shiftEntity.setPostId(String.valueOf(postService.findIdByPostName(shiftEntity.getPostName()).getId()));
        shiftService.insert(shiftEntity);
    }

    @RequestMapping("/update")
    public int update(ShiftEntity shiftEntity){

        shiftEntity.setMarketId(String.valueOf(marketService.findIdByMarketName(shiftEntity.getMarketName()).getId()));
        shiftEntity.setPostId(String.valueOf(postService.findIdByPostName(shiftEntity.getPostName()).getId()));
        return shiftService.update(shiftEntity);
    }

    @RequestMapping("/deleteById")
    public int  deleteById(int id){

        return shiftService.deleteById(id);
    }

    @RequestMapping("/deleteIdList")
    public int  deleteIdList(Long[] id){
        System.out.println(id);
        return shiftService.deleteIdList(id);
    }

    @RequestMapping("/findId")
    public ShiftEntity  findId(String id){
        return shiftService.findId(id);
    }

    @RequestMapping("/findAll")
    public List<ShiftEntity>  findAll(ShiftEntity shiftEntity){
        System.out.println(shiftEntity);
        return shiftService.findAll(shiftEntity);
    }

    //根据市场名称和岗位名称查找班次名称
    @RequestMapping("/findByMarketNameAndPostName")
    public List<ShiftEntity> findByMarketNameAndPostName(String marketName,String postName){
        return shiftService.findByMarketNameAndPostName(marketName,postName);
    }

    //根据市场名称，查找所有的班次列表
    @RequestMapping("/findAllByMarketName")
    public List<ShiftEntity> findAllByMarketName(String marketName){
        return shiftService.findAllByMarketName(marketName);
    }

    //根据市场名称，岗位名称查找所有的班次列表
    @RequestMapping("/findAllByMarketNameAndPostName")
    public List<ShiftEntity> findAllByMarketNameAndPostName(String marketName,String postName){
        return shiftService.findByMarketNameAndPostName(marketName,postName);
    }

    //根据市场名称，岗位名称，班次名称查找所有的班次列表
    @RequestMapping("/findAllByMarketNameAndPostNameAndShiftName")
    public List<ShiftEntity> findAllByMarketNameAndPostNameAndShiftName(String marketName,String postName,String shiftName){
        return shiftService.findAllByMarketNameAndPostNameAndShiftName(marketName,postName,shiftName);
    }




}
